//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "LigandPDBFilter.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String* filenameBindingProfile  = NULL;
  String* filenameListLigands     = NULL;
  String* folderHetAtmIn          = NULL;
  String* folderHetAtmOut         = NULL;
  
  if (argc < 4) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./ExtractSeparatedBindingDataInterAndIntraDomains <In File - Ligand FASTA Profile>";
    cout <<                                                  " <In File - List of Ligands>";
    cout <<                                                  " <Folder with HETATM Files - In>";
    cout <<                                                  " <Folder with HETATM Files - Out>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    filenameBindingProfile  = new String(argv[1]);
    filenameListLigands     = new String(argv[2]);
    folderHetAtmIn          = new String(argv[3]);
    folderHetAtmOut         = new String(argv[4]);
    
    cout << "------------------------------------------------------------------------------------------------------" << endl;
    cout << " In File - Ligand FASTA Profile : " << argv[1] << endl;
    cout << "      In File - List of Ligands : " << argv[2] << endl;
    cout << "  Folder with HETATM Files - In : " << argv[3] << endl;
    cout << " Folder with HETATM Files - Out : " << argv[4] << endl;
    cout << "------------------------------------------------------------------------------------------------------" << endl;
    
  }
  
  LigandPDBFilter* ligandPDBFilter = new LigandPDBFilter ();
  
  cout << "Preparing Files..." << endl;
  ligandPDBFilter->BindingProfile()->FilenameBindingProfile(filenameBindingProfile);
  ligandPDBFilter->BindingProfile()->FilenameListLigands(filenameListLigands);
  ligandPDBFilter->LocationPDBHet(folderHetAtmIn);
  ligandPDBFilter->LocationPDBOut(folderHetAtmOut);
  
  cout << "Loading the data..." << endl;
  if (!ligandPDBFilter->LoadData())
    cout << "Error Loading data!" << endl;

  cout << "Extract the PDB files of ligands in a list..." << endl;
  ligandPDBFilter->WritePDBForEachLigand();
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (ligandPDBFilter)        delete ligandPDBFilter;
  
  if (filenameBindingProfile) delete filenameBindingProfile;
  if (filenameListLigands)    delete filenameListLigands;
  if (folderHetAtmIn)         delete folderHetAtmIn;
  if (folderHetAtmOut)        delete folderHetAtmOut;

  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

